package tecpointbenchmark.model.modules;

import tecpointbenchmark.model.dto.ResultDTO;

/**
 * The Benchmarking Module Superclass
 * 
 * @author Fredrik Gullberg
 */
abstract public class BenchmarkModule extends Thread {

    private String moduleName;
    private String shortDescription;
    private String longDescription;
    private boolean continueBenchmarking;
    private ResultDTO result;

    /**
     * @param r The result object for this module.
     */
    public BenchmarkModule(ResultDTO r) {
        // Store the result object
        this.result = r;
    }

    /**
     * Fetches a short description of the module.
     * @return A <code>String</code> containing a description of the module.
     */
    public String getShortDescription() {
        return this.shortDescription;
    }

    /**
     * Fetches a long description of the module.
     * @return A <code>String</code> containing a description of the module.
     */
    public String getLongDescription() {
        return this.longDescription;
    }

    /**
     * Fetches the name of the module.
     * @return A <code>String</code> containing the name of the module.
     */
    public String getModName() {
        return this.moduleName;
    }

    /**
     * Fetches the boolean var for continuing the benchmarking-loop
     * @return The boolean var, true if the module continues benchmarking
     */
    public boolean getContinueBenchmarking() {
        return this.continueBenchmarking;
    }

    /**
     *
     * @return
     */
    public ResultDTO getResult() {
        return this.result;
    }

    /**
     * Starts the benchmarking procedure.
     *
     * @return Returns the result as a <code>Result</code>-object.
     * @throws Exception
     */
    public void runBenchmark() {
        // Overwritten in subclasses
    }

    /**
     * Stops the benchmarking procedure.
     */
    public void stopBenchmark() {
        continueBenchmarking = false;
        if (tecpointbenchmark.startup.Main.debug) {
            System.out.println("continueBenchmarking set to: " + continueBenchmarking);
        }
    }

    /**
     * The method that is called when the ModuleHandler calls start()
     *
     */
    @Override
    public void run() {
        this.runBenchmark();
    }

    /**
     * Sets the module name
     * @param s The name of the module
     */
    public void setModuleName(String s) {
        this.moduleName = s;
    }

    /**
     * Sets the long description of the module
     * @param s The long description of the module
     */
    public void setLongDescription(String s) {
        this.longDescription = s;
    }

    /**
     * Sets the short description of the module
     * @param s The short description of the module
     */
    public void setShortDescription(String s) {
        this.shortDescription = s;
    }

    /**
     * Sets the boolean var for continue benchmarking
     * @param s True if the module will continue the benchmarking-loop
     */
    public void setContinueBenchmarking(boolean b) {
        this.continueBenchmarking = b;
    }
}
